package com.richy.toweather.presenter;

import android.util.Log;

import com.richy.toweather.contract.MainContract;
import com.richy.toweather.entity.WeatherEntity;
import com.richy.toweather.model.MainModel;

import java.util.ArrayList;
import java.util.List;

/**
 * @FileName MainPresenter
 * @Description MainPresenter
 * @Author x925914554@gmail.com
 * @Company
 * @CreateDate 18-11-13
 * @LastModifyDate 18-11-13
 * @Since
 * @Version
 */
public class MainPresenter implements MainContract.Presenter {
    private static final String TAG = "MainPresenter";
    final List<WeatherEntity> mWeatherEntityList = new ArrayList<>();
    private MainContract.View mView;
    private MainContract.Model mModel;
    private MainModel.CallBack mCallBack = new MainModel.CallBack() {
        @Override
        public void onDataError(Throwable e) {
            Log.e(TAG, "onDataError: " + e);
        }

        @Override
        public void onData(WeatherEntity weatherEntity) {
//            Log.d(TAG, "onData: " + weatherEntity);
//            mWeatherEntityList.add(weatherEntity);
//            mView.setData(mWeatherEntityList);
        }

        @Override
        public <T> void onDatas(List<T> weatherEntities) {
            mView.showLoading(false);
            mView.setData((List<WeatherEntity>) weatherEntities);
        }
    };

    public MainPresenter(MainContract.View view) {
        mView = view;
        mModel = new MainModel(mCallBack);
    }

    @Override
    public void getDatas(String[] cities) {
        mView.showLoading(true);
//        for (String city : cities) {
//            mModel.getData(city);
//        }
        mModel.getDatas(cities);
    }
}
